﻿using System;
using System.ComponentModel;

using DevExpress.Xpo;
using DevExpress.Data.Filtering;

using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Persistent.Base.Security;
using System.Collections.Generic;
using System.Security;

namespace SpeedSCM.Module
{
    [NavigationItem("基本信息")]
    [ImageName("BO_Role")]
    [RuleCriteria(null, DefaultContexts.Delete, "职员.Count == 0", "由于该角色下有用户存在所以不能删除", SkipNullOrEmptyValues = true)]
    [MapInheritance(MapInheritanceType.ParentTable)]
    public class 角色 : RoleBase, ICustomizableRole, IRole
    {
        public 角色(Session session)
            : base(session)
        {
        }
        private string _描述;
        [Custom("Caption", "描述")]
        public string 描述
        {
            get { return _描述; }
            set { SetPropertyValue<string>("描述", ref _描述, value); }
        }
        [Association("职员-角色")]
        public XPCollection<职员> 职员
        {
            get
            {
                return GetCollection<职员>("职员");
            }
        }
        IList<IUser> IRole.Users
        {
            get
            {
                return new ListConverter<IUser, 职员>(职员);
            }
        }
        void ICustomizableRole.AddPermission(IPermission permission)
        {
            base.AddPermission(permission);
        }
    }
}
